package com.vincent.druid.page;

import com.alibaba.druid.sql.PagerUtils;
import com.alibaba.druid.util.JdbcConstants;

/**
 * @author vincent
 * @date 2019/4/17
 * @description
 * 分页工具，count工具使用
 */
public class PageUtils {
    public static void main(String[] args) {
        String sql = getSql();

        // mysql， pg， oracle分页， hive不支持分页，只能limit
        String mysqllimit = PagerUtils.limit(sql, JdbcConstants.MYSQL, 10, 10);
        System.out.println("mysql = " + mysqllimit);
        String pglimit = PagerUtils.limit(sql, JdbcConstants.POSTGRESQL, 10, 10);
        System.out.println("\n postgresql = " +pglimit);
        String oracleLimit = PagerUtils.limit(sql, JdbcConstants.ORACLE, 10, 10);
        System.out.println("\n oracle = " +oracleLimit);

        // 判断是否含有limit
        boolean b = PagerUtils.hasUnorderedLimit(oracleLimit, JdbcConstants.ORACLE);

        System.out.println("has limit " +b);

        // 进行count
        String count = PagerUtils.count(sql, JdbcConstants.MYSQL);
        System.out.println("\n "+ count);

        // 进行count
        String orcount = PagerUtils.count(sql, JdbcConstants.ORACLE);
        System.out.println("\n "+ orcount);
    }

    public static String getSql() {
        String sql = "select * from userinfo where id=666";

        return sql;
    }
}
